package com.iot.http2.controller;

import com.iot.http2.entity.DemoEntity;
import com.iot.http2.service.BusinessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * demo controller
 * @author guoguoqiang
 * @since 20201130
 */
@Slf4j
@RestController
@RequestMapping("/demo")
public class DemoController {

    private BusinessService businessService;

    @Autowired
    public DemoController(BusinessService businessService) {
        this.businessService = businessService;
    }

    @GetMapping(value = "/hello")
    public String hello(@RequestParam String name) {
        return businessService.hello(name);
    }

    @GetMapping(value = "/findById")
    public DemoEntity findById(Long id) {
        return businessService.findById(id);
    }

    @GetMapping("/common")
    public String common() {
        return "common";
    }

    @GetMapping(value = "/inner")
    public String inner(@RequestParam String name) {
        return businessService.callInner(name);
    }

    @RequestMapping("/request")
    public String request(HttpServletRequest request) {
        String name =  request.getParameter("name");
        log.info("request it, value:{}", name);
        return "name param=" + name;
    }

}
